#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : bigDataProject 
@File    : customer_api.py
@IDE     : PyCharm 
@Author  : Mario
@Date    : 2022/11/14 11:16 
@Describe: 中台会员相关接口
"""
from api.middle_api.base_middle_api import BaseMiddleAPI
from utils.common.common_control import get_json_result


class CustomerAPI(BaseMiddleAPI):
    def get_customer_info(self, brand_code, phone):
        """
        获取会员基础信息
        :param brand_code: 品牌编码
        :param phone: 手机号
        :return:
        """
        payload = '{"brandCode":"' + str(brand_code) + '","phone":"' + phone + '"}'
        response = self.http_request('catering-backend/customer/info/info', payload, "中台获取会员基础信息")
        return response

    def get_customer_list(self, brand_code, phone):
        """
        获取会员列表
        :param brand_code: 品牌编码
        :param phone: 手机号
        :return:
        """
        payload = '{"brandCode":"' + str(brand_code) + '","phone":"' + phone + '"}'
        response = self.http_request('scrm-admin/customer/base/list', payload, "中台获取会员列表")
        return response

    def customer_point_operation(self, brand_code, phone, change_point):
        """
        会员积分操作
        :param brand_code: 品牌编码
        :param phone: 手机号
        :param change_point: 操作积分，可以减
        :return:
        """
        vip_info = self.get_customer_info(brand_code, phone)
        customer_id = str(get_json_result(vip_info, '$..customerId'))
        payload = '{"brandCode":"' + brand_code + '","customerId":"' + customer_id + '","changePoint":"' + change_point + '"}'
        response = self.http_request('scrm-admin/customer/point/save', payload)
        return response


if __name__ == '__main__':
    test = CustomerAPI('sit')
    test.get_customer_list('823882', '18682241673')
